/**
 * @file models/overview.js
 * @author
 */
import {routerRedux} from 'dva/router';
import api from '../api';

import {timeRangeList, benchCodeList,industryList} from '../utils/dataConfig'

export default {
  namespace : 'prolist',
  state : {
    productList:[],
    timeRangeList:[],
    benchCodeList:[],
    industryList:[],
    BpdtsearchId:'',//产品模糊搜索id
    BisShow:true,
  },
  subscriptions : {
    setup({dispatch, history}) {
      history.listen(({pathname, query}) => {
        if (pathname === '/investmentSummary/investDashboard'||pathname === '/achievement/equity/brinson'||pathname === '/fundAnalysis/custodianEvaluation') {
          dispatch({type: 'queryConfig', payload: query})
          // dispatch({type:'clearState'})
        }
      })
    }
  },
  effects : {
    * queryConfig({
      payload
      }, {call, put, select}) {
        const {beginDate, cBenchCode, endDate, lPortId, timeRange} = payload
        // if(beginDate&&cBenchCode&&endDate&&lPortId&&timeRange){
        //   yield put({
        //     type: 'query',
        //     payload,
        //   });
        // }
        yield put({
          type: 'querySuccess',
          payload: {
            timeRangeList,
            industryList,
          }
        })

    },
    * query({
      payload
      }, {call, put, select}) {

      const {beginDate, cBenchCode, endDate, lPortId, timeRange} = payload
      const prolist = yield call(api.getBrinsonPdt, payload);
      const productList = prolist.data.map((item, i) => ({
        id: item.productId + '',
        value: `${item.productCode}：${item.productName}`
      }))
      yield put({
        type: 'querySuccess',
        payload: {
          productList,
          // benchCodeList:benchCodeList.concat(productList),
        }
      });

    },
    // * getListPdt({ payload:query }, { call, put }) {
    //     const response = yield call(api.getBrinsonPdt, query);
    //     const productList = response.data.map((item, i) => ({
    //       id: item.productId + '',
    //       value: `${item.productCode}：${item.productName}`
    //     }))
    //     yield put({
    //       type: 'getListPdtSuccess',
    //       payload: { productList } ,
    //     });
    //   },

  },
  reducers : {
    setState(state, {payload}) {
      return {
        ...state,
        ...payload
      }
    },
    clearState(state) {
      return {
        productList:[{
          id:'',
          value:''
        }],
        timeRangeList:[{
          name: '',
          value: ''
        }],
        benchCodeList:[{
          id:'',
          value:''
        }],
        industryList:[{
          name: '',
          value: ''
        }],
			}
    },
    querySuccess(state, {payload}) {
      return {
        ...state,
        ...payload
      }
    },
    // getListPdtSuccess(state,{payload}){
    //   // console.log('payload',payload)
    //     return {
    //       ...state,
    //       BListPdt:payload.productList
    //     }
    //   }

  }
};
